package com.ruoyi.controller;

import com.ruoyi.domain.NewsType;
import com.ruoyi.domain.NewsWithType;
import com.ruoyi.domain.common.PageResult;
import com.ruoyi.domain.common.ResponseResult;
import com.ruoyi.service.INewsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 新闻类型Controller
 *
 * @author ruoyi
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/newsType")
public class NewsTypeController {

    @Autowired
    private INewsTypeService newsTypeService;

    /**
     * 查询新闻类型列表
     */
//    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public ResponseResult list(NewsType newsType) {
        PageResult<NewsType> newsTypePageResult = new PageResult<>();
        List<NewsType> list = newsTypeService.selectNewsTypeList(newsType);
        newsTypePageResult.setTotal(list.size());
        newsTypePageResult.setRecords(list);
        return ResponseResult.success(newsTypePageResult);
    }

    @GetMapping("/newsRanking")
    public ResponseResult newsRanking(){
        PageResult<NewsWithType> newsWithTypePageResult = new PageResult<>();
        return ResponseResult.success(newsWithTypePageResult);
    }

    /**
     * 导出新闻类型列表
     */
//    @PreAuthorize("@ss.hasPermi('system:type:export')")
//    @Log(title = "新闻类型", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, NewsType newsType) {
//        List<NewsType> list = newsTypeService.selectNewsTypeList(newsType);
//        ExcelUtil<NewsType> util = new ExcelUtil<NewsType>(NewsType.class);
//        util.exportExcel(response, list, "新闻类型数据");
//    }

    /**
     * 获取新闻类型详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public ResponseResult getInfo(@PathVariable("id") Integer id) {
        return ResponseResult.success(newsTypeService.selectNewsTypeById(id));
    }

    /**
     * 新增新闻类型
     */
//    @PreAuthorize("@ss.hasPermi('system:type:add')")
//    @Log(title = "新闻类型", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseResult add(@RequestBody NewsType newsType) {
        return ResponseResult.success(newsTypeService.insertNewsType(newsType));
    }

    /**
     * 修改新闻类型
     */
//    @PreAuthorize("@ss.hasPermi('system:type:edit')")
//    @Log(title = "新闻类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseResult edit(@RequestBody NewsType newsType) {
        return ResponseResult.success(newsTypeService.updateNewsType(newsType));
    }

    /**
     * 删除新闻类型
     */
//    @PreAuthorize("@ss.hasPermi('system:type:remove')")
//    @Log(title = "新闻类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResponseResult remove(@PathVariable Integer[] ids) {
        return ResponseResult.success(newsTypeService.deleteNewsTypeByIds(ids));
    }
}
